package dime.parser.bancodobrasil;

import java.io.InputStream;
import java.util.Calendar;
import java.util.Date;

import net.rim.device.api.i18n.SimpleDateFormat;

import dime.commons.DateUtils;
import dime.parser.CsvUtils;
import dime.parser.Parser;
import dime.persistence.model.Bill;

/**
 * @author Joao Galli
 * 
 */
public class BancoDoBrasilParser implements Parser {

	public Bill[] parse(InputStream inputStream) {
		String[][] parse = CsvUtils.parse(inputStream);

		Bill[] contas = new Bill[parse.length];

		for (int i = 1; i < parse.length - 1; i++) {
			String[] item = parse[i];

			Bill bill = new Bill();

			for (int j = 0; j < item.length; j++) {
				String value = item[j];

				switch (j) {
				case 0:
					Date data = DateUtils.parseFullDate(value);
					bill.setData(new Long(data.getTime()));
					break;

				case 2:
					bill.setNome(value);
					break;

				case 5:
					bill.setValor(Double.valueOf(value));
				}
			}

			contas[i] = bill;
		}

		return contas;
	}

}
